package com.gzhryc.shared_device.oem.micro.iot;

import com.gzhryc.common.logging.Logger;
import com.gzhryc.shared_device.bxscn.core.BXSCNConstants;
import com.gzhryc.shared_device.bxscn.core.IBXSCNNetworkService;
import com.gzhryc.shared_device.bxscn.core.protocol.v1.V1_BXSCNNetworkService;
import com.gzhryc.shared_device.cdb.core.CDBConstants;
import com.gzhryc.shared_device.cdb.core.ICDBNetworkService;
import com.gzhryc.shared_device.cdb.core.protocol.v1.V1_CDBNetworkService;
import com.gzhryc.shared_device.cdcz.core.CDCZConstants;
import com.gzhryc.shared_device.cdcz.core.ICDCZNetworkService;
import com.gzhryc.shared_device.cdcz.core.protocol.v1.V1_CDCZNetworkService;
import com.gzhryc.shared_device.cdcz.core.protocol.v2.V2_CDCZNetworkService;
import com.gzhryc.shared_device.iot.core.IOTClient;

/**
 * IOT网络服务工厂
 * 
 * @author zhanghao
 * @version 2022-09-04
 */
public class LocalNetworkServiceUtils {

	static Logger log = Logger.getLogger(LocalNetworkServiceUtils.class);

	public static ICDCZNetworkService getCDCZNetworkService(Long iotId) {
		IOTClient iotClient = IOTServerNodeFactory.self().getIOTClient(iotId);
		if(iotClient != null) {
			if (CDCZConstants.ProtocolTypeV1.equals(iotClient.getIOTNote().getProtocolType())) {
				return new V1_CDCZNetworkService(iotClient);
			}else if (CDCZConstants.ProtocolTypeV2.equals(iotClient.getIOTNote().getProtocolType())) {
				return new V2_CDCZNetworkService(iotClient);
			}else{
				log.error("IOT节点[{{0}}]不是充电插座协议，其协议为：{{1}}",iotId,iotClient.getIOTNote().getProtocolType());
			}
		}else{
			log.error("未找到IOT节点[{{0}}]的配置",iotId);
		}
		return null;
	}

	public static ICDBNetworkService getCDBNetworkService(Long iotId) {
		IOTClient iotClient = IOTServerNodeFactory.self().getIOTClient(iotId);
		if(iotClient != null) {
			if (CDBConstants.ProtocolTypeV1.equals(iotClient.getIOTNote().getProtocolType())) {
				return new V1_CDBNetworkService(iotClient);
			}else{
				log.error("IOT节点[{{0}}]不是共享充电宝协议，其协议为：{{1}}",iotId,iotClient.getIOTNote().getProtocolType());
			}
		}else{
			log.error("未找到IOT节点[{{0}}]的配置",iotId);
		}
		return null;
	}

	public static IBXSCNNetworkService getBXSCNNetworkService(Long iotId) {
		IOTClient iotClient = IOTServerNodeFactory.self().getIOTClient(iotId);
		if(iotClient != null) {
			if (BXSCNConstants.ProtocolTypeV1.equals(iotClient.getIOTNote().getProtocolType())) {
				return new V1_BXSCNNetworkService(iotClient);
			}else{
				log.error("IOT节点[{{0}}]不是共享便携式电池协议，其协议为：{{1}}",iotId,iotClient.getIOTNote().getProtocolType());
			}
		}else{
			log.error("未找到IOT节点[{{0}}]的配置",iotId);
		}
		return null;
	}
}
